{template 'public/header'}
{template 'public/comhead'}

{if $operation == 'display'}
<div class="main">
    <div class="panel panel-default" id="uploaddata" style="display: none;">
        <div class="panel-body">
            <form action="" method="post" class="navbar-form navbar-left" enctype="multipart/form-data">
                <input type="hidden" name="leadExcel" value="true">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="weisrc_dish" />
                <input type="hidden" name="do" value="UploadExcel" />
                <input type="hidden" name="ac" value="goods" />
                <input type="hidden" name="storeid" value="{$storeid}" />
                <span class="input-group">
                    <input name="viewfile" id="viewfile" type="text" value="" class="form-control" style="width:300px;" readonly>
			        <span class="input-group-btn">
                        <a class="btn btn-default ms_br">
                            <label for="unload" class="ms_mp" >选择...</label>
                        </a>
                        <input type="submit" style="border-radius: 0px;" class="btn btn-success" value="上传"
                               onclick="if(document.getElementById('viewfile').value==''){alert('请先选择上传文件!');return false;}">
                        <a class="btn btn-primary ms_mb" href="../addons/weisrc_dish/example/example_goods.xls">下载导入模板
                        </a>
                    </span>
                    <input type="file" name="inputExcel" id="unload" class="form-control" style="display: none;"
                           onchange="document.getElementById('viewfile').value=this.value;this.style.display='none';">
                </span>
            </form>
            <style>
                .ms_br {
                    border-radius: 0px;border-left-width: 0px;
                }
                .ms_mp {
                    margin: 0px;padding:0px;
                }
                .ms_mb {
                    border-top-left-radius:0px;border-bottom-left-radius:0px;
                }
            </style>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-body">
            <form action="./index.php" method="post" class="form-horizontal form" onsubmit="return formcheck(this)"  enctype="multipart/form-data">
                <a class="btn btn-default" href="{php echo $this->createWebUrl('goods', array('op' => 'post', 'storeid' => $storeid))}"><i class="fa fa-plus"></i> 添加商品</a>
                <a class="btn btn-default" href="{php echo $this->createWebUrl('category', array('op' => 'display', 'storeid' => $storeid))}"><i class="fa fa-list"></i> 商品分类</a>
                <a class="btn btn-success" href="#" onclick="$('#uploaddata').slideToggle();">批量导入</a>
            </form>
        </div>
    </div>
    <div class="panel panel-info">
        <div class="panel-heading">筛选</div>
        <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="weisrc_dish" />
                <input type="hidden" name="do" value="goods" />
                <input type="hidden" name="storeid" value="{$storeid}" />
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label" style="width: 100px;">关键字</label>
                    <div class="col-sm-2 col-lg-2">
                        <input class="form-control" name="keyword" id="" type="text" value="{$_GPC['keyword']}">
                    </div>
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label" style="width: 100px;">商品分类</label>
                    <div class="col-sm-2 col-lg-2">
                        <select style="margin-right:15px;" name="category_id" class="form-control">
                            <option value="0">请选择商品分类</option>
                            {loop $category $row}
                            <option value="{$row['id']}" {if $row['id'] == $_GPC['category_id']} selected="selected"{/if}>{$row['name']}</option>
                            {/loop}
                        </select>
                    </div>
                    <div class="col-sm-2 col-lg-2">
                        <button class="btn btn-default"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
        <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data">
        <input type="hidden" name="storeid" value="{$storeid}" />
        <table class="table table-hover">
			<thead class="navbar-inner">
				<tr>
                    <th class='with-checkbox' style="width:2%;"><input type="checkbox" class="check_all" /></th>
                    <th style="width:10%;">顺序</th>
					<th style="width:6%;">序号</th>
                    <th style="width:12%">商品名称</th>
                    <th style="width:10%;">分类</th>
                    <th style="width:8%;">价格</th>
                    <th style="width:8%;">打包费</th>
                    <th style="width:8%;">赠送积分</th>
                    <th style="width:8%;">每日库存</th>
                    <th style="width:8%;">剩余库存</th>
                    <th style="width:7%;">总销量</th>
					<th style="width:10%;">是否上架</th>
					<th style="width:10%;">操作</th>
				</tr>
			</thead>
			<tbody>
				{loop $list $item}
				<tr>
                    <td class="with-checkbox"><input type="checkbox" name="check" value="{$item['id']}"></td>
                    <td><input type="text" class="form-control" name="displayorder[{$item['id']}]" value="{$item['displayorder']}"></td>
					<td>{$item['id']}</td>
                    <td>
                        <img src="{php echo tomedia($item['thumb']);}" width="50" onerror="this.src='./resource/images/nopic.jpg';" style="border-radius: 3px;" /><br/>
                        {$item['title']}</td>
                    <td>
                        {if !empty($category[$item['pcate']])}{$category[$item['pcate']]['name']}{/if}
                        {if !empty($label[$item['labelid']])}<br/><span class="label label-info">标签:{$label[$item['labelid']]['title']}</span>{/if}
                    </td>
                    <td>
                        {$item['marketprice']}
                    </td>
                    <td>
                        {$item['packvalue']}
                    </td>
                    <td>
                        {$item['credit']}
                    </td>
                    <td>
                        {if $item['counts']==-1}
                        <span class="label label-default">未启用</span>
                        {else}
                        {$item['counts']}
                        {/if}
                    </td>
                    <td>
                        {if $item['counts']==-1}

                        <span class="label label-default">未启用</span>
                        {else}
                        {php echo $item['counts']-$item['today_counts']}
                        {/if}
                    </td>
                    <td>
                        {$item['sales']}
                    </td>
					<td>{if $item['status']}<span class="label label-success">已上架</span>{else}<span class="label label-error">已下架</span>{/if}</td>
					<td style="text-align:right;">
						<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('goods', array('id' => $item['id'], 'op' => 'post', 'storeid' => $storeid))}" title="编辑">编辑</a>&nbsp;&nbsp;<a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('goods', array('id' => $item['id'], 'op' => 'delete', 'storeid' => $storeid))}" onclick="return confirm('此操作不可恢复，确认删除？');return false;" title="删除">删除</a>
					</td>
				</tr>
				{/loop}
			</tbody>
			<tr>
				<td colspan="10">
					<input name="token" type="hidden" value="{$_W['token']}" />
					<input type="submit" class="btn btn-primary" name="submit" value="批量更新排序" />
                    <input type="button" class="btn btn-primary" name="btndeleteall" value="批量删除" />
				</td>
			</tr>
		</table>
        {$pager}
        </form>
        </div>
    </div>
</div>
<script type="text/javascript">
<!--
	var category = {php echo json_encode($children)};
//-->
$(function(){
    $(".check_all").click(function(){
        var checked = $(this).get(0).checked;
        $("input[type=checkbox]").attr("checked",checked);
    });

    $("input[name=btndeleteall]").click(function(){
        var check = $("input[type=checkbox][class!=check_all]:checked");
        if(check.length < 1){
            alert('请选择要删除的商品!');
            return false;
        }
        if(confirm("确认要删除选择的商品?")){
            var id = new Array();
            check.each(function(i){
                id[i] = $(this).val();
            });
            var url = "{php echo $this->createWebUrl('goods', array('op' => 'deleteall', 'storeid' => $storeid))}";
            $.post(
                url,
                {idArr:id},
                function(data){
                    alert(data.error);
                    location.reload();
                },'json'
            );
        }
    });

});
</script>
{elseif $operation == 'post'}
{php include $this->template('web/goods_detail');}
{/if}
{template 'common/footer'}